package com.xiaohao.server.chromosome.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaohao.server.chromosome.bean.ChromosomeImage;
import com.xiaohao.server.chromosome.mapper.ChromosomeImageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class ChromosomeImageService {
    @Autowired
    private ChromosomeImageMapper chromosomeImageMapper;

    public List<ChromosomeImage> queryList(ChromosomeImage chromosomeImage) {
        LambdaQueryWrapper<ChromosomeImage> queryWrapper = new LambdaQueryWrapper<>(chromosomeImage);
        queryWrapper.orderByAsc(ChromosomeImage::getNumber,ChromosomeImage::getZonePrefix,ChromosomeImage::getZone);
        queryWrapper.select(tableFieldInfo -> !"path".equals(tableFieldInfo.getColumn()));
        return chromosomeImageMapper.selectList(queryWrapper);
    }

    public ChromosomeImage queryOne(ChromosomeImage chromosomeImage) {
        LambdaQueryWrapper<ChromosomeImage> queryWrapper = new LambdaQueryWrapper<>(chromosomeImage);
        return chromosomeImageMapper.selectOne(queryWrapper);
    }

    public ChromosomeImage queryById(Integer id) {
        return chromosomeImageMapper.selectById(id);
    }

    public Integer save(ChromosomeImage chromosomeImage) {
        if (Objects.nonNull(chromosomeImage) && Objects.nonNull(chromosomeImage.getId())) {
            return chromosomeImageMapper.updateById(chromosomeImage);
        } else {
            return chromosomeImageMapper.insert(chromosomeImage);
        }
    }

    public Integer delete(Integer id) {
        return chromosomeImageMapper.deleteById(id);
    }


}
